<template>
  <div>
    <el-card class="box-card-header">
      <el-form :inline="true" :model="formInline" class="demo-form-inline">
        <el-form-item label="订单编号"><el-input v-model="formInline.user" placeholder="请输入订单编号" clearable></el-input></el-form-item>
        <el-form-item label="商品名">
         <el-input v-model="formInline.region" placeholder="请输入商品名" clearable></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="searchDo(formInline.user)">查询</el-button>
          <el-button type="primary" @click="clearable()">清空查询</el-button>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="showInsert">新建</el-button>
        </el-form-item>
      </el-form>
    </el-card>

    <!-- 表格卡片-->
    <el-card class="box-card-content" v-bind:style="{ minHeight: Height + 'px' }">
      <el-table ref="multipleTable" :data="tableData" tooltip-effect="dark" style="width: 100%" @selection-change="handleSelectionChange">
        <el-table-column type="selection" width="55"></el-table-column>

        <el-table-column prop="orderno" label="编号"></el-table-column>

        <el-table-column prop="ordercode" label="订单编号" show-overflow-tooltip></el-table-column>

        <el-table-column prop="customerid" label="用户名"></el-table-column>

        <el-table-column prop="productid" label="商品名"></el-table-column>

        <el-table-column prop="money" label="单价"></el-table-column>

        <el-table-column prop="state" label="状态"></el-table-column>

        <el-table-column  prop="addtime" label="下单时间" align="center">
        </el-table-column>

        <el-table-column align="center" label="操作" width="220">
          <template slot-scope="scope">
            <el-button size="mini" @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
            <el-button size="mini" type="danger" @click.native.prevent="deleteRow(scope.$index, tableData)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-card>
    <el-pagination style="margin-top: 20px;" @current-change="handleCurrentChange" :current-page.sync="currentPage1"
      :page-size="pageSize" background='true' layout="total, prev, pager, next" :total="totleSize">
    </el-pagination>
  </div>
</template>

<script>
export default {
  data() {
    return {
      pageSize: 5,
      currentPage1: 1,
      totleSize: 0,
      Height: 0,
      tableData: [],
      multipleSelection: [],
      formInline: {
        user: '',
        region: ''
      }
    };
  },
  methods: {
      getdata(){
        this.getRequest('Sales/order/getOrderList?beginPage=' + this.currentPage1 + '&pageSize=' + this.pageSize)
          .then(successResponse => {
            if (successResponse.data.status == 200) {

              this.tableData = successResponse.data.obj;
              this.totleSize = successResponse.data.totleSize;
              this.getdata1();
            } else
              this.$message.error(successResponse.data.msg);
          })
          .catch(failResponse => {
            this.$message.error('网络不通畅');
          })
      },
      getdata1(){
        this.getRequest('Sales/order/getCusList?beginPage=' + this.currentPage1 + '&pageSize=' + this.pageSize)
          .then(successResponse => {
            if (successResponse.data.status == 200) {
              var index=0;
              var value=successResponse.data.obj;
              this.tableData.forEach(item =>{
                this.tableData[index].customerid=value[index].name
                index++;
              })
            } else
              this.$message.error(successResponse.data.msg);
          })
          .catch(failResponse => {
            this.$message.error('网络不通畅');
          })
      },
      handleCurrentChange(val) {
       this.getdata()
      },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    handleEdit(index, row) {
      console.log(index, row);
    },
    deleteRow(index, rows) {
      rows.splice(index, 1);
    },
    onSubmit() {
      console.log('submit!');
    },
    handleClick(tab, event) {
      console.log(tab, event);
    }
  },
  mounted() {
    //动态设置内容高度 让footer始终居底   header+footer的高度是100
    this.Height = document.documentElement.clientHeight - 375; //监听浏览器窗口变化
    window.onresize = () => {
      this.Height = document.documentElement.clientHeight - 375;
    };
  }
};
</script>

<style>
.box-card-header {
  width: 100%;
}
.box-card-content {
  width: 100%;
}
</style>
